#include "board.h"
#include "rtthread.h"

static void Receive_Thread_Rntry(void* parameter);
static void Send_Thread_Entry(void* parameter);

static rt_thread_t receive_thread = RT_NULL;
static rt_thread_t send_thread = RT_NULL;

static rt_mailbox_t test_mail = RT_NULL;

char *test_str1 = "this is a mail test 1";/* 邮箱消息 test1 */
char *test_str2 = "this is a mail test 2";/* 邮箱消息 test2 */
int main(void)
{	
		ILI9341_GramScan ( 6 );//设置显示模式
		LED_Color(LED_OFF);
		test_mail = rt_mb_create("test_mail",10,RT_IPC_FLAG_FIFO);
	
    receive_thread = 
			rt_thread_create("receive_thread",Receive_Thread_Rntry,RT_NULL,512,3,20);
	  rt_thread_startup(receive_thread);
	
		send_thread = 
				rt_thread_create("send_thread",Send_Thread_Entry,RT_NULL,512,3,20);
		rt_thread_startup(send_thread);	
}

static void Receive_Thread_Rntry(void* parameter)
{
	rt_err_t uwRet = RT_EOK;
	char *r_str;
	while(1)
	{
		uwRet = rt_mb_recv(test_mail,
											 (rt_uint32_t*)&r_str,
											 RT_WAITING_FOREVER);
		
		if(uwRet == RT_EOK)
		{
			rt_kprintf("The data is: %s\n",r_str);
		}
	}
}

static void Send_Thread_Entry(void* parameter)
{
	rt_err_t uwRet = RT_EOK;
	while(1)
	{
		if(GET_KEY1)
		{
			rt_mb_send(test_mail,(rt_uint32_t)test_str1);
		}
		if(GET_KEY2)
		{
			rt_mb_send(test_mail,(rt_uint32_t)test_str2);
		}
		rt_thread_delay(20);
	}
}
